﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Threading;

namespace YinYueTai.Model
{
    public class MV : INotifyPropertyChanged
    {
        public MV()
        {

        }



        public string Title { get; set; }

        public string Artist { get; set; }

        public string Describe { get; set; }

        public string ID { get; set; }

        protected string imgSrc;
        public string ImgSrc
        {
            get
            {
                return "http://www.yinyuetai.com" + imgSrc;
            }
            set
            {
                imgSrc = value;
                DownloadImg(ImgSrc);
            }
        }

        protected BitmapImage img;
        public BitmapImage Img
        {
            get
            {
                return img;
            }

            set
            {
                img = value;
                if (PropertyChanged != null)
                    PropertyChanged(null, new PropertyChangedEventArgs("Img"));
            }
        }

        public int MyProperty { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;

        private void DownloadImg(string src)
        {
            WebClient wc = new WebClient();

            wc.Headers["Accept"] = "image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5";
            wc.Headers["Accept-Encoding"] = "gzip, deflate";
            wc.Headers["User-Agent"] = "Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; Microsoft; XDeviceEmulator)";
            wc.Headers["Accept-Language"] = "zh-cn,en-us;q=0.5";
            wc.Headers["UA-CPU"] = "x86";
            wc.Headers["Referer"] = "http://www.yinyuetai.com/";
            wc.OpenReadAsync(new Uri(src));
            wc.OpenReadCompleted += (s, e) =>
            {
                try
                {
                    Img = new BitmapImage();

                    Img.SetSource(e.Result);
                }
                catch (Exception ex)
                {

                    MessageBox.Show("图片下载错误!"+ex.Message);
                }

            };
        }


    }
}
